package my.graduation.controller.common;

import my.graduation.dto.AlertDto;
import my.graduation.enums.HttpCodeEnums;
import my.graduation.result.Result;
import my.graduation.util.SMSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: RavenLyn
 * @Date: 2025-03-02
 */
@RestController
@RequestMapping
public class SMSController {

    @Autowired
    private SMSUtil smsUtil;

    @PostMapping("/admin/alert")
    public Result doAlert(@RequestBody AlertDto dto){
        return alertMethod(dto);
    }

    private Result alertMethod(AlertDto dto) {
        try{
            String mobile = dto.getMobile();
            String name = dto.getName();
            String time = dto.getTime();
            String params = "**name**:" + name + ",**time**:" + time;
            smsUtil.postSMS(mobile,params);
            return Result.success();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(HttpCodeEnums.SMS_SEND_FAILED);
        }
    }
}
